home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 2: Applications
/
Linux Cubed Series 2 - Applications.iso
/
hamradio
/
tnos-2.000
/
tnos-2
/
hasher.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-22
|
1KB
|
70 lines
#include <stdio.h>
#ifdef __bsdi__
#include <stdlib.h>
#endif
#ifdef __STDC__
#define __ARGS(x) x
#else
#define __ARGS(x) ()
#endif
#include <string.h>
#include "md5.c"
#if !defined(_lint) && !defined(MSDOS)
static char rcsid[] OPTIONAL = "$Id: hasher.c,v 1.5 1996/06/22 18:20:37 root Exp root $";
#endif
char* basename(char*);
char *
basename (char *name)
{
char *retval;
if (!(retval = strrchr (name, '/')))
retval = name;
return (retval);
}
/* Compute MD5 hash of local file */
int
main(int argc, char **argv)
{
FILE *fp;
MD5_CTX md;
char buf[BUFSIZ];
int len, k;
if (argc < 2) {
fprintf (stdout, "%s: Usage\n\t%s filename [filename]...\n",basename(argv[0]), basename(argv[0]));
exit (1);
}
for (k = 1; k < argc; k++) {
fp = fopen (argv[k], "rb");
if (!fp) {
fprintf (stdout, "%s: Can't open file '%s'\n",basename(argv[0]), argv[k]);
continue;
}
MD5Init(&md);
while((len = fread(buf,1,BUFSIZ,fp)) != 0)
MD5Update(&md,(unsigned char *)buf,len);
fclose (fp);
MD5Final(&md);
printf ("%s:\t%-16s\t", basename(argv[0]), argv[k]);
for(len=0;len<16;len++) /* Write hashed password */
printf("%02x",md.digest[len] & 0xff);
putchar ('\n');
}
return 0;
}